<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('order_id');
            $table->string('order_bn', 100)->index()->comment('订单编号');
            $table->bigInteger('member_id')->comment('会员ID');
            $table->enum('status', ['active','invalid','done'])->default('active')->comment('状态: active 活跃 invalid 作废 done 完成');
            $table->enum('pay_status', ['notpay','paid', 'refunded'])->default('notpay')->comment('状态: notpay 未支付 paid 已支付 returned 已退款');
            $table->enum('ship_status', ['notdelivery','shipped', 'returned'])->default('notdelivery')->comment('状态: notdelivery 未发货 shipped 已发货 returned 已退货');
            $table->float('goods_price', 8, 2)->default('0.00')->comment('商品总额');
            $table->float('amount', 8, 2)->default('0.00')->comment('订单总额');
            $table->float('discount_amount', 8, 2)->default('0.00')->comment('优惠金额');
            $table->float('paid_amount', 8, 2)->default('0.00')->comment('支付金额');
            $table->timestamp('payed_time')->nullable()->comment('支付时间');
            $table->integer('address_id')->default(0)->comment('收货地址');
            $table->string('payment_code', 50)->nullable()->comment('支付方式');
            $table->text('remark')->nullable()->comment('订单备注');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
